package net.uiiang.android.BiscuitBoxDemo.text;

import net.uiiang.android.BiscuitBox.R;
import android.app.Activity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.InputType;
import android.text.method.NumberKeyListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EditTextDemo extends Activity {
    EditText ediText3;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.edittext_demo1);
        EditText editText1 = (EditText) super.findViewById(R.id.edittext01);
        // 屏蔽软件键盘 只显示输入法可选字
        editText1.setInputType(InputType.TYPE_NULL);
        editText1.setText("屏蔽软件键盘");

        EditText editText2 = (EditText) findViewById(R.id.edittext02);
        editText2.setText("点击粘贴按钮,通过ClipboardManager将文本粘贴到下方编辑框");
        Button button1 = (Button) super.findViewById(R.id.button01);
        button1.setOnClickListener(new ParseText(editText1, editText2));

        ediText3 = (EditText) findViewById(R.id.edittext03);
//        ediText3.setText("得到当前输入法,屏蔽软键盘后继续使用当前输入法");
        ediText3.setHint("得到当前输入法,屏蔽软键盘后继续使用当前输入法");
        ediText3.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                int inType = ediText3.getInputType(); // backup the input type
                ediText3.setInputType(InputType.TYPE_NULL); // disable soft
                // input
                ediText3.onTouchEvent(event); // call native handler
                ediText3.setInputType(inType); // restore input type
                return true; // consume touch even}});
            }
        });
        

        EditText ediText4 = (EditText) findViewById(R.id.edittext04);
//        ediText4.setFocusable(false);
//        ediText4.setFocusableInTouchMode(false);
//        ediText4.setEnabled(false);
        ediText4.setKeyListener(new NumberKeyListener() { 
         
            public int getInputType() { 
                return InputType.TYPE_NULL; 
            } 
         
            @Override 
            protected char[] getAcceptedChars() { 
                return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 
            } 
        }); 

    }

    private class ParseText implements OnClickListener {
        TextView fromView;
        TextView toView;

        public ParseText(TextView fromView, TextView toView) {
            this.fromView = fromView;
            this.toView = toView;
        }

        public void onClick(View v) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(fromView.getText());
            toView.setText(clipboard.getText());
        }
    }
}
